
import java.util.ArrayList;
import java.util.List;

public class TaskThreadDemo {
    public static void main(String[] args) {
        // Create tasks
        Runnable printHello = new PrintChar("你好", 50);
        Runnable printStudents = new PrintStudents();
        Runnable printGoodbye = new PrintChar("再见", 50);

        // Create threads
        Thread thread1 = new Thread(printHello);
        Thread thread2 = new Thread(printStudents);
        Thread thread3 = new Thread(printGoodbye);

        // Start threads
        thread1.start();
        thread2.start();
        thread3.start();
    }
}

// The task for printing a specified character for a specified number of times
class PrintChar implements Runnable {
    private String charToPrint; // The character to print
    private int times; // The times to repeat

    /** Construct a task with the specified character and number of times to print the character */
    public PrintChar(String c, int t) {
        charToPrint = c;
        times = t;
    }

    /** Override the run() method to tell the system what task to perform */
    public void run() {
        for (int i = 0; i < times; i++) {
            System.out.print(charToPrint);
        }
    }
}


class PrintStudents implements Runnable {
    private List<String> students;

    
    public PrintStudents() {
        students = new ArrayList<>();
        students.add("李志杰");
        students.add("陈星宇");
        students.add("樊荣荣");
  
    }

    /** Tell the thread how to run */
    public void run() {
        for (String student : students) {
            System.out.println(student);
        }
    }
}
